package com.back.campus_back.controller;


import com.back.campus_back.domain.WantedGoods;
import com.back.campus_back.service.impl.WantedGoodsServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  求购商品控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-17
 */
@RestController
@RequestMapping("/wanted-goods")
@Api(tags = "求购平台的控制类")
public class WantedGoodsController {

    @Autowired
    WantedGoodsServiceImpl wantedGoodsService;
    /*
     * 查询全部求购
     * */
    @ApiOperation("查询全部求购")
    @GetMapping("/AllWantsGoods")
    public List<WantedGoods> AllWantsGoods(){
        return wantedGoodsService.AllWantsGoods();
    }

    /*
     * 查询全部求购：分页
     * */
    @ApiOperation("查询全部求购：分页")
    @GetMapping("/AllWantsGoods/{current}/{size}")
    public IPage<WantedGoods> AllWantsGoods(@PathVariable("current")Integer current, @PathVariable("size")Integer size){
        return wantedGoodsService.AllWantsGoods(current,size);
    }

    /*
     * 根据用户的id查询用户发布的商品信息
     * */
    @ApiOperation("根据用户的id查询用户发布的商品信息")
    @GetMapping("/findWantedGoodsByStuId/{student_id}/{current}/{size}")
    public IPage<WantedGoods> findWantedGoodsByStuId(
            @PathVariable("student_id")Integer student_id, @PathVariable("current")Integer current, @PathVariable("size")Integer size){
        return wantedGoodsService.findWantedGoodsByStuId(student_id,current,size);
    }

    /*
     * 发布求购
     * */
    @ApiOperation("发布求购")
    @PostMapping("/insertWantedGoods")
    public String insertWantedGoods(@RequestBody WantedGoods wantedGoods){
        return wantedGoodsService.insertWantedGoods(wantedGoods);
    }

    /*
     * 用户更新求购信息
     * */
    @PostMapping("/updateWantedGoods")
    public String updateWantedGoods(@RequestBody  WantedGoods wantedGoods){
        return  wantedGoodsService.updateWantedGoods(wantedGoods);
    }


    /*
     * 删除求购信息
     * */
    @GetMapping("/deleteWantedGoodsById/{want_id}")
    public String deleteWantedGoodsById( @PathVariable("want_id")Integer want_id){
        return wantedGoodsService.deleteWantedGoodsById(want_id);
    }


}

